<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <script src="../js/lib/jquery-1.10.2.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</head>
<body>

<div class="container-fluid" style="margin-top: 20px">
    <form id="form-like">
        <div class="row">
            <div class="col-md-4 ">
                <div class="form-group">
                    <label for="" class="col-sm-3 control-label">姓名</label>
                    <div class="col-sm-9">
                        <input name="name" class="form-control"  placeholder="姓名">
                    </div>
                </div>
            </div>
            <div class="col-md-4 ">
                <div class="form-group">
                    <label class="col-sm-3 control-label">电话</label>
                    <div class="col-sm-9">
                        <input name="tel" class="form-control"  placeholder="电话">
                    </div>
                </div>
            </div>
            <div class="col-md-4 ">
                <div class="form-group">
                    <label for="" class="col-sm-4 control-label">保险类型</label>
                    <div class="col-sm-8">
                        <input name="intention" class="form-control"  placeholder="保险类型">
                    </div>
                </div>
            </div>
        </div>
        <div class="row" style="margin-top: 20px">
            <div class="col-md-3 col-md-offset-9" style="text-align: right">
                <input id="btn-like" type="button" class="btn btn-warning" value="查询"/>
            </div>
        </div>
    </form>


<!--    <div class="row">-->
<!--        <div class="col-md-2 col-md-offset-10">-->
<!--            <button type="button" class="btn btn-warning">新增公共客户</button>-->
<!--        </div>-->
<!--    </div>-->
    <div class="row" style="margin-top: 20px">
        <div class="col-md-12">
            <table id="tab-show" class="table table-striped" style="width: 90%;text-align: center" align="center">
                <tr style="font-weight: 700">
                    <td>姓名</td>
                    <td>性别</td>
                    <td>手机号</td>
                    <td>投保意向</td>
                    <td>操作</td>
                </tr>
<!--                <tr>-->
<!--                    <td>张三</td>-->
<!--                    <td>男</td>-->
<!--                    <td>13200000000</td>-->
<!--                    <td>-->
<!--                         <button data-toggle="modal" data-target="#myModal2" type="button" class="btn btn-primary">获取客户</button>-->
<!--                    </td>-->
<!--                </tr>-->

            </table>
        </div>
    </div>

    <!--分页 begin-->
    <div class="row">
        <div class="col-md-12">
            <nav aria-label="Page navigation" style="float: right">
                <ul class="pagination">
<!--                    <li><a href="#">1</a></li>-->
                </ul>
            </nav>

        </div>
    </div>
    <!--分页 end-->
    <!-- 获取 begin -->
    <!-- Modal -->
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" >获取客户</h4>
                </div>
                <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-3">获取潜在顾问工号</div>
                            <div class="col-sm-9">
                                <input id="take-uid" class="form-control" type="text">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" id="but-zr" class="btn btn-primary btn-one-zr">获取</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 获取 end -->

</div>
<script type="text/javascript">
    $(function () {

        count();
        show(1);

    })

    function count (){
        $.ajax({
            url:"/customer/countPublic",
            type:"get",
            dataType:"json",
            success:function (result) {

                if(result.state==2000){
                    let num=result.data/5;
                    if(num>parseInt(num)){
                        num++;
                    }
                    for(let i=1;i<=num;i++){
                        $(".pagination").append(" <li><a >"+i+"</a></li>");
                    }

                }else {
                    alert("出现错误")
                }
                $(".pagination").children().click(function () {
                    console.log("点击获取坐标")
                    let index=$(this).text();

                    $("#tab-show").children().remove()
                    $("#tab-show").append("<tr style=\"font-weight: 700\">\n" +
                        "                    <td>姓名</td>\n" +
                        "                    <td>性别</td>\n" +
                        "                    <td>手机号</td>\n" +
                        "                    <td>投保意向</td>\n" +
                        "                    <td>操作</td>\n" +
                        "                </tr>")
                    show(index)
                })
            }
        });
    }


    function show(index) {
        $.ajax({
            url:"/customer/showPublic?index="+index,
            type:"get",
            dataType:"json",
            success:function (result) {
                if(result.state==2000){
                    for(let list of result.data ){
                        let sex;
                        if(list.sex==0){
                            sex="女";
                        }else {
                            sex="男";
                        }

                        $("#tab-show").append("<tr cid='"+list.id+"'>" +
                            "<td>"+list.name+"</td>" +
                            "<td>"+sex+"</td>" +
                            "<td>"+list.tel+"</td>" +
                            "<td>"+list.intention+"</td>" +
                            "<td>" +
                            "<button data-toggle=\"modal\" data-target='' type=\"button\" class='btn btn-primary get-cust'>获取</button>\n" +
                            "</td>" +
                            "</tr>")
                    }
                    //获取
                    $(".get-cust").click(function () {
                        if (confirm("确定获取该潜在客户吗？")) {
                        let cid=$(this).parents("tr").attr("cid")

                       // $("#but-zr").click(function () {
                            $.ajax({
                                url:"/customer/updatePublic?cid="+cid,
                                type:"post",
                                dataType:"json",
                                success:function (result) {
                                    if(result.state==2000){
                                        alert("获取成功")
                                        location.reload(false)
                                    }else {
                                        alert(result.message)
                                    }
                                }
                            })
                       // })
                        }
                    })

                }
            }
        })
    }

    $("#btn-like").click(function () {
        $("#tab-show").children().remove()
        $("#tab-show").append("<tr style=\"font-weight: 700\">\n" +
            "                    <td>姓名</td>\n" +
            "                    <td>性别</td>\n" +
            "                    <td>手机号</td>\n" +
            "                    <td>投保意向</td>\n" +
            "                    <td>操作</td>\n" +
            "                </tr>")

        $.ajax({
            url:"/customer/likePublic",
            data:$("#form-like").serialize(),
            type:"post",
            dataType: "json",
            success:function (result) {
                if(result.state==2000){

                    for(list of result.data ){
                        let sex;
                        if(list.sex==0){
                            sex="女";
                        }else {
                            sex="男";
                        }

                        $("#tab-show").append("<tr cid='"+list.id+"'>" +
                            "<td>"+list.name+"</td>" +
                            "<td>"+sex+"</td>" +
                            "<td>"+list.tel+"</td>" +
                            "<td>"+list.intention+"</td>" +
                            "<td>" +
                            "<button data-toggle=\"modal\" data-target=\"#myModal2\" type=\"button\" class='btn btn-primary get-cust'>转让</button>\n" +
                            "</td>" +
                            "</tr>")


                    }

                    //获取
                    $(".get-cust").click(function () {
                        let cid=$(this).parents("tr").attr("cid")
                        if (confirm("确定获取该潜在客户吗？")) {
                       // $("#but-zr").click(function () {
                            $.ajax({
                                url:"/customer/updatePublic?cid="+cid,
                                type:"post",
                                dataType:"json",
                                success:function (result) {
                                    if(result.state==2000){
                                        alert("获取成功")
                                        location.reload(false)
                                    }else {
                                        alert(result.message)
                                    }
                                }
                            })
                        }

                    })



                }
            }
        })
    })





</script>

</body>
</html>